<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

session_start();

if(!isset($_SESSION['install']) || !is_array($_SESSION['install'])) $_SESSION['install'] = array();

$requestUri = str_replace('index.php', '', $_SERVER['REQUEST_URI']);
$requestUri = str_replace('//', '/', $requestUri);
$requestUri = explode('?', $requestUri);
$requestUri = $requestUri[0];
$pathPrefix = rtrim('/'.trim($requestUri, '/'), '/');
define('PATH_PREFIX', $pathPrefix);

require_once('install/functions.php');

$error = false;
$errors = array();
$success = array();
$content = '';

if(get('success')!=''){
    $success[] = get('success');
}


// lets check if they have cookies enabled
if(!isset($_SESSION['install'])){
    if(get('session')==1){
        // cookies not enabled.
        $error = true;
        $errors[] = 'Please enable cookies';
        $_SESSION['install'] = 1;
    }else{
        $_SESSION['install'] = array();
        $requestUri = explode('?', $_SERVER['REQUEST_URI']);
        redirect($requestUri[0].'?session=1');
    }
}

ob_start();

if(!$error){
    // now lets begin our install
    switch(get('step')){
        case 'paths':
            include('install/paths.php');
        break;
        case 'settings':
            include('install/settings.php');
        break;
        case 'review':
            include('install/review.php');
        break;
        case 'database':
            include('install/database.php');
        break;
        default:
            redirect('?step=database');
        break;
    }

}

$content .= ob_get_contents();
ob_end_clean();

if(count($errors)>0) $errorMsg = '<div class="jfxt-error-messages"><div class="jfxt-error-messages-inner">
<ul class="jfx-error-msg"><li>'.implode('</li><li>', $errors).'</li></ul></div></div>';
else $errorMsg = '';

if(count($success)>0) $successMsg = '<div class="jfxt-error-messages"><div class="jfxt-error-messages-inner">
<ul class="jfx-success-msg"><li>'.implode('</li><li>', $success).'</li></ul></div></div>';
else $successMsg = '';

$content = $errorMsg.$successMsg.$content;

echo renderTemplate($content);
